// package: learn-go
// filename: main
// author: Administrator@gmail.com
// time: 2023/8/31 22:43

package main

import (
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
)

type ParentNode struct {
	Val   int    `json:"val"`
	Token string `json:"token"`
	*ChildNode
}

type ChildNode struct {
	Uid   int    `json:"uid"`
	Uname string `json:"uname"`
}

type UserModel struct {
	AccountLoginRes
}

type AccountLoginRes struct {
	Token   string `bson:"token,omitempty" json:"token,omitempty"           dc:"登录token"`
	Expires int64  `bson:"expires,omitempty" json:"expires,omitempty"         dc:"登录有效期"`

	AdminUser
}

type AdminUser struct {
	//PublicFields `bson:",inline"`
	Uid          int    `bson:"uid" json:"uid" dc:"用户uid"`
	Username     string `bson:"username" json:"username" dc:"帐号"`
	PasswordHash string `bson:"passwordHash" json:"passwordHash" dc:"密码"`
	Role         int    `bson:"role,omitempty" json:"role,omitempty" dc:"用户权限（1：管理员，2：编辑(新建)权限 3:查看）"`
	Status       int    `bson:"status" json:"status" dc:"用户状态 "`
	Email        string `bson:"email" json:"email" dc:"用户邮箱"`
	OpenId       string `bson:"openId" json:"openId" dc:"微信openId"`
	UnionID      string `bson:"unionId,omitempty" json:"unionId,omitempty" dc:"微信unionid"`
}

func main() {

	//res :=make(map[string]interface{})
	res := map[string]interface{}{
		"token":        "action",
		"expires":      123456789,
		"uid":          1,
		"username":     "admin",
		"role":         1,
		"status":       1,
		"email":        "diogoxiang@example.com",
		"openId":       "123456789",
		"unionId":      "123456789",
		"passwordHash": "e10adc3949ba59abbe56e057f20f883e",
	}

	p := new(UserModel)

	if err := gconv.Scan(res, &p); err != nil {
		fmt.Println(err)
	}

	g.Dump(p)

}
